package com.hwhhhh.graduationproject.config;

import com.hwhhhh.graduationproject.interceptors.JWTInterceptor;
import com.hwhhhh.graduationproject.resolvers.CurrentUserMAR;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Description 配置
 * Created by Hwhhhh on 2021/3/3 21:35
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/api/**")     // 拦截所有url
                .excludePathPatterns("/api/users/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(getCurrentUserMAR());
    }

    @Bean
    public CurrentUserMAR getCurrentUserMAR(){
        return new CurrentUserMAR();
    }
}
